home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 121 / Computer Shopper 121 / Computer Shopper 121.iso / Internet / Demon / TURNPIKE.1 / CLASSES.ZIP / MS / APPLET / AppletAudioClip.class (.txt) next >
Encoding:
Java Class File  |  1997-04-14  |  1.8 KB  |  75 lines

  1. package ms.applet;
  2.  
  3. import java.applet.AudioClip;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import sun.audio.AudioData;
  9. import sun.audio.AudioDataStream;
  10. import sun.audio.AudioPlayer;
  11. import sun.audio.AudioStream;
  12. import sun.audio.ContinuousAudioDataStream;
  13.  
  14. public class AppletAudioClip implements AudioClip {
  15.    URL url;
  16.    AudioData data;
  17.    InputStream stream;
  18.  
  19.    public AppletAudioClip(URL var1) {
  20.       InputStream var2 = null;
  21.  
  22.       try {
  23.          try {
  24.             URLConnection var5 = var1.handler.openConnection(var1);
  25.             var5.setAllowUserInteraction(true);
  26.             var2 = var5.getInputStream();
  27.             this.data = (new AudioStream(var2)).getData();
  28.          } finally {
  29.             if (var2 != null) {
  30.                var2.close();
  31.             }
  32.  
  33.          }
  34.  
  35.       } catch (IOException var9) {
  36.          this.data = null;
  37.       }
  38.    }
  39.  
  40.    public synchronized void play() {
  41.       this.stop();
  42.       if (this.data != null) {
  43.          this.stream = new AudioDataStream(this.data);
  44.          AudioPlayer.player.start(this.stream);
  45.       }
  46.  
  47.    }
  48.  
  49.    public synchronized void loop() {
  50.       this.stop();
  51.       if (this.data != null) {
  52.          this.stream = new ContinuousAudioDataStream(this.data);
  53.          AudioPlayer.player.start(this.stream);
  54.       }
  55.  
  56.    }
  57.  
  58.    public synchronized void stop() {
  59.       if (this.stream != null) {
  60.          AudioPlayer.player.stop(this.stream);
  61.  
  62.          try {
  63.             this.stream.close();
  64.          } catch (IOException var1) {
  65.          }
  66.       }
  67.    }
  68.  
  69.    public String toString() {
  70.       StringBuffer var10000 = new StringBuffer();
  71.       Class var1 = this.getClass();
  72.       return var10000.append((var1.isInterface() ? "interface " : "class ") + var1.getName()).append("[").append(this.url).append("]").toString();
  73.    }
  74. }
  75.